﻿<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title>骨医快线</title>
    <link rel="stylesheet" href="../css/gy.css" />
    <link href="../css/mui.plus.css" rel="stylesheet" />
    <style>
    	span.pat-status1, span.pat-status2 {
		    padding: 0 3px;
    		margin-left: 5px;
		    border: 1px solid #aaa;
		    border-radius: 5px;
		    font-size: 12px;
		    color: #ff924e;
		}
		span.pat-status1 {
			border: 1px solid #ff924e;
		}
		span.pat-status2 {
			color: #999;
		}
		.mui-table-view-chevron .mui-table-view-cell {
		    padding-right: 15px;
		}
		.mui-table-view:after {
			height: 0;
		}
		.mui-badge {
			padding: 4px !important;
			background-color: #FF924E;
		}
		.date {
			padding: 0!important;
		}
		/*顶栏处理*/
		.mui-bar.mui-bar-nav {
			background: #fff;
			border: none;
		}
		.mui-bar.mui-bar-nav .mui-title {
			font-size: 16px;
			color: #999;
		}
		.mui-bar:after {
		    position: absolute;
		    left: 0;
		    right: 0;
		    bottom: 0;
		    height: 1px;
		    background-color: #ccc;
		    content: '';
		    -webkit-transform: scaleY(0.5);
		    transform: scaleY(0.5);
		}
    </style>
</head>
<body>
	<div class="pat-header-mat"></div>
	<header class="mui-bar mui-bar-nav" style="background: #fff;">
		<h1 class="mui-title">骨医快线</h1>
	</header>
    <div class="mui-content mui-scroll-wrapper oe-home" id="refreshContainer">
        <div class="mui-scroll">
        	<div class="oe-btn-img-group" style="padding-top:10px; flex-shrink: 0;">
	            <div id="btnInvite" class="oe-btn-db">
	                <img src="../images/btn-invite-visit.png" alt="随访邀请" style="width: 100%;" />
	            </div>
	            <div class="oe-btn-db">
	                <img id="btn-club" src="../images/btn-association .png" alt="骨研社" style="width: 100%;" />
	            </div>
	        </div>
	
			<div class="oe-title-line">随访记录</div>
	        <ul class="mui-table-view mui-table-view-chevron oe-list1" id="itvList">
				<div class="oe-emp">
					<img src="../images/blank_page/empty-follow@2x.png"/>
				</div>	  
	        </ul>
	        
	        <div style="padding-top: 15px; padding-left: 15px;">
				<p>*欢迎登陆我们的官网<br />http://www.orthexpress.com/</p>
			</div>
			
        </div>
    </div>
    
	<script id="tmp-itv" type="text/html">
		{{each data as v i}}
			<li class="mui-table-view-cell"
				data-recid = "{{v.rec_id}}" 
				data-paid  = "{{v.rec_pa_id}}" 
				data-foid  = "{{v.rec_fo_id}}"
				data-fostage = "{{v.fo_stage !== 'UN_BIND' ? 'BD' : 'UN'}}">
				<div class="mui-slider-right mui-disabled">
					<a class="mui-btn mui-btn-red">删除</a>
				</div>
				<div class="mui-slider-handle">
					<div class="first-line"  style="overflow: hidden;">
						<span>{{v.rec_name}}</span>
						<span>{{v.rec_sex}}</span>
						<span>{{v.rec_age}}</span>
						<span class="{{v.fo_stage == 'UN_BIND' ? 'pat-status1' : 'pat-status2'}} mui-pull-right">
							{{v.fo_stage == 'UN_BIND' ? '未绑定' : '已绑定'}}
						</span>
						{{if v.fo_red_flag === 'UNREAD'}}
						<span class="mui-badge mui-pull-right"></span>
						{{/if}}
					</div>
		            <div class="second-line">
		            	<span>{{v.rec_surgery_name}}</span>
		            	<span class="date">{{v.fo_ctime}}</span>
		            </div>
				</div>
			</li>
		{{/each}}	
	</script>
	
    <script src="../js/mui.min.js"></script> 
    <script src="../js/app.js"></script>
    <script src="../js/lib/template.js"></script>
    <script type="text/javascript" charset="utf-8">
        (function ($, doc) {
        	var tmpData = {};
        	var foId, isBind, foStage;
        	var itvList = document.getElementById("itvList");
        	
            //页面初始化，传入相关参数
            $.init({
				pullRefresh : {
			    container:".mui-scroll-wrapper",//下拉刷新容器标识，querySelector能定位的css选择器均可，比如：id、.class等
			    down: {
			    	contentdown : '下拉可以刷新',
			    	contentover : '释放立即刷新',
			    	contentrefresh : '正在刷新...',
					callback: pulldownRefresh
				},
				up : {
				      height:150,//可选.默认50.触发上拉加载拖动距离
				      auto:false,//可选,默认false.自动上拉加载一次
				      contentrefresh : "正在加载...",//可选，正在加载状态时，上拉加载控件上显示的标题内容
				      callback : pullUpRefresh 
				    }
			  }
      		});
      		
      		
      		function pulldownRefresh(){	
      			getList();
            	setTimeout(function(){
            		mui('#refreshContainer').pullRefresh().endPulldownToRefresh();
            	},1000);
            };
            
            var upNum = 1;
            function pullUpRefresh(){
            	setTimeout(function(){
            		getNewList();
            		$('#refreshContainer').pullRefresh().endPullupToRefresh(false)
        		},500);
            };
            
            function getList(){
            	upNum = 1;
            	app.net.get('c_followup/show_list', { fo_dr_id: app.storage.getUserId(), page_num: 0, page_size: 10 }, function(data){
            		if(data && data.code == 100){
            			tmpData = data;
            			var html = template('tmp-itv', tmpData);
            			if(html){
            				itvList.innerHTML = html;
            			}
            		}
            	});
            };
            
            function getNewList(){
            	app.net.get('c_followup/show_list', { fo_dr_id: app.storage.getUserId(), page_num: ++upNum, page_size: 10 }, function(data){
            		if(data && data.code == 100){
            			if(/空数据/.test(data.msg)){
            				return;
            			}else {
            				//数据填入模板
            				tmpData = data;
	            			var html = template('tmp-itv', tmpData);
	            			itvList.innerHTML += html;
            				$('#refreshContainer').pullRefresh().endPullupToRefresh(false)
            			}
            		}
            	});
            }
            
            $('.mui-content').on('tap', '#btn-club', function(){
            	$.openWindow({
            		url: 'club/home.html',
            		waiting: {
            			autoShow: false
            		}
            	});
            });
            
            $.plusReady(function () {
                getList(); 
                
				window.addEventListener('start', function(){
                	getList();
                })
				
                
                $('.mui-content').on('tap', '#btnInvite', function(){
                	$.confirm(' ', '选择新建随访方式', ['从现有病历中新建','添加新用户的随访','取消'], function(e){
                		if(e.index == 0){
                			var pageMain = plus.webview.getWebviewById('main');
                			$.fire(pageMain, 'toSecond', null);
                			$.openWindow(pageMain);
                		}else if(e.index == 1){
                			$.openWindow({
                				url : 'interview/interview-add.html',
                				waiting : {
                					autoShow : false
                				}
                			}); 
                		}
                	});
                });
                
                $('#itvList').on('tap', 'li', function(){
                	var rec_id = this.dataset.recid,
                		pa_id  = this.dataset.paid,
                		fo_id  = this.dataset.foid,
                		fo_stage = this.dataset.fostage;
					$.openWindow({
						url : 'interview/detail-home.html',
						waiting : {
							autoShow : false
						},
						extras : {
							pa_id    : pa_id,
							fo_id    : fo_id,
							rec_id   : rec_id,
							fo_stage : fo_stage
						}
					});
                });
                
                var btnArray = ['确认', '取消'];
                $('#itvList').on('tap', '.mui-btn',function(){
                	var self = this;
                	var li = self.parentNode.parentNode;
                	foId = li.dataset.foid;
                	isBind = li.dataset.fostage;
                	
                	if(isBind === 'BD'){
                		plus.nativeUI.toast('已绑定患者无法删除');
                		$.swipeoutClose(li);
                		return;
                	}
                	
                	$.confirm('确认删除该随访记录？', '骨医快线', btnArray, function(e) {
						if (e.index == 0) {
							li.parentNode.removeChild(li);
							app.net.post('c_followup/delete', {fo_id : foId}, function(data){
								if(data && data.code == 100){
									plus.nativeUI.toast('删除成功');
								}
							});
						} else {
							setTimeout(function() {
								$.swipeoutClose(li);
							}, 0);
						}
					});
                });
                 
            });
        }(mui, document));
    </script>
</body>
</html>